<template>
  <div class="div">
    <PageTitle title="审核内容中心"></PageTitle>
    <el-button type="primary" @click="Audit">审核通过</el-button>
    <el-table stripe :data="tableData" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55"></el-table-column>
      <el-table-column label="内容封面">
        <template slot-scope="scope">
          <div class="img" v-if="!scope.row.url.endsWith('mp4')">
            <img
              :src="scope.row.url"
              @click="handlePictureCardPreview(scope.row.url)"
              class="list-img"
            />
          </div>
          <a v-else :href="scope.row.url" target="_blank">
            <video :src="scope.row.url"></video>
          </a>
        </template>
      </el-table-column>
      <el-table-column prop="fication_name" label="品牌"></el-table-column>
      <el-table-column label="操作" width="140">
        <template slot-scope="scope">
          <router-link
            :to="{name: 'ContentreviewDetail', params: {id: scope.row.id, url:  scope.row.url }}"
            class="color-theme margin-right"
          >查看</router-link>
          <!--         <el-button type="text" @click="change(scope.row.url,scope.row.id)">修改</el-button>-->
          <el-button type="text" @click="del(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="pagination-wrapper">
      <el-pagination
        layout="prev, pager, next"
        @current-change="pageChange"
        :page-size="pageSize"
        :total="totalCount"
        :current-page="pageNum"
      ></el-pagination>
    </div>
    <el-dialog :visible.sync="dialogVisible">
      <img width="100%" :src="dialogImageUrl" />
    </el-dialog>
  </div>
</template>

<script>
import PageTitle from "@/components/pageTitle/PageTitle.vue";
// import _ from 'lodash'
export default {
  name: "GoodsList",
  components: {
    PageTitle
  },
  activated() {
    this._getList();
  },
  data() {
    return {
      tableData: [],
      pageNum: 1,
      totalCount: 0,
      pageSize: 10,
      status: "0", //  筛选参数
      search: "", //搜索参数
      dialogImageUrl: "",
      dialogVisible: false,
      ids:null
    };
  },
  methods: {
    //多选
    handleSelectionChange(val) {
      console.log("多选---------", val);
      this.ids = val.map(item => {
        return item.id;
      });
    },
    //批量审核通过
    Audit(e) {
      console.log("点击了审核通过");
      if (this.ids.length > 0) {
        this.$confirm("确认通过审核？")
          .then(() => {
            console.log("点击了确认");
            this.submitForm();
          })
          .catch(() => {
            console.log("点击了取消");
          });
      } else {
        this.$message({
          message: "请选择要审核的数据",
          type: "warning"
        });
      }
    },
    //点击过审
    async submitForm() {
      console.log("点击提交");
      this.loading = true;
      let data = await this.$axios({
        url: this.$api + "/v1/goods/repairlist",
        method: "POST",
        data: {
          id: this.ids.join(",")
        }
      });
      this.loading = false;
      console.log("审核结果---------", data);
      if (data.data.code ==0) {
        this.$message.success(data.data.data)
        this._getList()
      }
    },
    //获取列表
    async _getList() {
      let {
        data: { data, code }
      } = await this.$axios({
        url: this.$api + "/v1/goods/triallist",
        method: "GET",
        params: {
          size: this.pageSize,
          current: this.pageNum
        }
      });
      if (code == 0) {
        this.tableData = data.items;
        this.totalCount = data.page.totalCount;
      }
    },
    goto(id) {
      this.$axios({
        // url: this.$api + '/v1/goods/strike',
        url: this.$api + "/goodsList/detailed/",
        method: "POST",
        data: {
          id
        }
      });
    },
    del(id) {
      this.$confirm("确认删除吗？", "提示", {
        type: "warning"
      }).then(() => {
        this._del(id);
      });
    },
    change(cid, id) {
      this.$axios({
        url: this.$api + "/v1/goodsList/within",
        method: "POST",
        data: {
          cid,
          id
        }
      });
    },
    async _del(id) {
      let {
        data: { code, data }
      } = await this.$axios({
        // url: this.$api + '/v1/goods/strike',
        url: this.$api + "/v1/goods/except",
        method: "POST",
        data: {
          id
        }
      });
      if (code == 0) {
        this.$message.success(data);
        this._getList();
      }
    },
    changeState(id, state) {
      this.$confirm("确认变更状态吗？", "提示", {
        type: "warning"
      }).then(() => {
        this._changeState(id, state);
      });
    },
    async _changeState(id, state) {
      let {
        data: { data, code }
      } = await this.$axios({
        url: this.$api + "/v1/goods/up",
        method: "POST",
        data: {
          id,
          state
        }
      });
      if (code === 0) {
        this.$message.success(data);
        this._getList();
      }
    },
    handleClick(s) {
      this.status = s;
      this.pageNum = 1;
      this._getList();
    },
    // handleSearch() {
    //   this.pageNum = 1
    //   this._getList()
    // },
    pageChange(pageNum) {
      this.pageNum = pageNum;
      this._getList();
    },
    handlePictureCardPreview(src) {
      this.dialogImageUrl = src;
      this.dialogVisible = true;
    }
  }
};
</script>

<style lang="scss" scoped>
@import "@/assets/css/select-bar.scss";
video {
  width: 100px;
  height: 60px;
  cursor: pointer;
}
.list-img {
  width: 100px;
  height: auto;
}
.el-button--text {
  text-decoration: none;
}
</style>